home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 676-700 / 699 / sizer / sizerw.c < prev   
C/C++ Source or Header  |  1995-03-18  |  15KB  |  368 lines

  1. /* SizerW.c
  2.  
  3.    by Fabbian G. Dufoe, III
  4.       350 Ling-A-Mor Terrace South
  5.       St. Petersburg, Florida  33705
  6.       813-823-2350
  7.  
  8.       GENIE: F.DUFOE3
  9.  
  10.    This software is public domain.  You may use it any way you wish.
  11.  
  12.    This code handles I/O between Sizer and the user.
  13.  
  14.    Revision summary:
  15.    15 October 1991: Initial release
  16.  
  17.    18 May 1992:
  18.       Changed version number to 1.1.
  19.       Changed CheckClose() and WaitClose() functions to static to match
  20.       prototypes, moved prototypes for static functions to this file.
  21.  
  22.    13 June 1992:
  23.       Changed version number to 1.2.
  24.       Changed display to show old file system (OFS) blocks and fast file
  25.       system (FFS) blocks.
  26.       Specified TOPAZ_EIGHTY for the display font.
  27.  
  28.    24 June 1992:
  29.       Removed copyright notice.
  30.  
  31.  -------------------------------------
  32. |Sizer 1992 by F. G. Dufoe, III       |
  33. |                                     |
  34. |  Bytes:              Directories:   |
  35. |  OFS Blocks:         Files:         |
  36. |  FFS Blocks:                        |
  37. |                                     |
  38. |Program completed.                   |
  39. |Select close gadget to exit.         |
  40.  -------------------------------------
  41.  
  42. */
  43.  
  44. #include <exec/types.h>
  45. #include <intuition/intuition.h>
  46. #include <libraries/dos.h>
  47. #include "Sizer.h"
  48.  
  49. #define INTUITION_REV 33
  50. #define GRAPHICS_REV 33
  51.  
  52. #ifndef __NOPROTO                                                             /* 18 May 1992 */
  53. #ifndef __PROTO                                                               /* 18 May 1992 */
  54. #define __PROTO(a) a                                                          /* 18 May 1992 */
  55. #endif                                                                        /* 18 May 1992 */
  56. #else                                                                         /* 18 May 1992 */
  57. #ifndef __PROTO                                                               /* 18 May 1992 */
  58. #define __PROTO(a) ()                                                         /* 18 May 1992 */
  59. #endif                                                                        /* 18 May 1992 */
  60. #endif                                                                        /* 18 May 1992 */
  61.  
  62. /* Prototypes for functions defined in SizerW.c */                            /* 18 May 1992 */
  63.  
  64. static int CheckClose __PROTO((struct Window *Window));                       /* 18 May 1992 */
  65. static void WaitClose __PROTO((struct Window *Window));                       /* 18 May 1992 */
  66.  
  67.  
  68. /* Use topaz 80 for text display. */                                          /* 13 June 1992 */
  69. static struct TextAttr TOPAZ80 =                                              /* 13 June 1992 */
  70. {                                                                             /* 13 June 1992 */
  71.    (STRPTR)"topaz.font", TOPAZ_EIGHTY, 0, 0                                   /* 13 June 1992 */
  72. };                                                                            /* 13 June 1992 */
  73.  
  74. /* Initialize IntuiText structures. */
  75. static struct IntuiText Title =
  76. {
  77.    1, 0,       /* UBYTE FrontPen, BackPen; */
  78.    JAM2,       /* UBYTE DrawMode; */
  79.    10,         /* SHORT LeftEdge; */
  80.    12,         /* SHORT TopEdge; */
  81.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  82.    "Sizer 1992 by F. G. Dufoe, III",                                          /* 24 June 1992 */
  83.                /* UBYTE *IText; */
  84.    NULL        /* struct IntuiText *NextText; */
  85. };
  86.  
  87. static struct IntuiText Bytes =
  88. {
  89.    1, 0,       /* UBYTE FrontPen, BackPen; */
  90.    JAM2,       /* UBYTE DrawMode; */
  91.    30,         /* SHORT LeftEdge; */
  92.    30,         /* SHORT TopEdge; */
  93.    &TOPAZ80,   /* struct TextAttr *ITextFont; */
  94.    "Bytes:",   /* UBYTE *IText; */
  95.    &Title      /* struct IntuiText *NextText; */
  96. };
  97.  
  98. static struct IntuiText OBlocks =                                             /* 13 June 1992 */
  99. {
  100.    1, 0,       /* UBYTE FrontPen, BackPen; */
  101.    JAM2,       /* UBYTE DrawMode; */
  102.    30,         /* SHORT LeftEdge; */                                          /* 13 June 1992 */
  103.    40,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  104.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  105.    "OFS Blocks:",                                                             /* 13 June 1992 */
  106.                /* UBYTE *IText; */                                            /* 13 June 1992 */
  107.    &Bytes      /* struct IntuiText *NextText; */                              /* 13 June 1992 */
  108. };
  109.  
  110. static struct IntuiText FBlocks =                                             /* 13 June 1992 */
  111. {
  112.    1, 0,       /* UBYTE FrontPen, BackPen; */
  113.    JAM2,       /* UBYTE DrawMode; */
  114.    30,         /* SHORT LeftEdge; */                                          /* 13 June 1992 */
  115.    50,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  116.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  117.    "FFS Blocks:",                                                             /* 13 June 1992 */
  118.                /* UBYTE *IText; */                                            /* 13 June 1992 */
  119.    &OBlocks    /* struct IntuiText *NextText; */                              /* 13 June 1992 */
  120. };
  121.  
  122. static struct IntuiText Dirs =
  123. {
  124.    1, 0,       /* UBYTE FrontPen, BackPen; */
  125.    JAM2,       /* UBYTE DrawMode; */
  126.    190,        /* SHORT LeftEdge; */                                          /* 13 June 1992 */
  127.    30,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  128.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  129.    "Directories:",
  130.                /* UBYTE *IText; */
  131.    &FBlocks    /* struct IntuiText *NextText; */                              /* 13 June 1992 */
  132. };
  133.  
  134. static struct IntuiText Files =
  135. {
  136.    1, 0,       /* UBYTE FrontPen, BackPen; */
  137.    JAM2,       /* UBYTE DrawMode; */
  138.    190,        /* SHORT LeftEdge; */                                          /* 13 June 1992 */
  139.    40,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  140.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  141.    "Files:",   /* UBYTE *IText; */
  142.    &Dirs       /* struct IntuiText *NextText; */                              /* 13 June 1992 */
  143. };
  144.  
  145. char ByteCount[20];
  146. static struct IntuiText ByteCt =
  147. {
  148.    1, 0,       /* UBYTE FrontPen, BackPen; */
  149.    JAM2,       /* UBYTE DrawMode; */
  150.    86,         /* SHORT LeftEdge; */
  151.    30,         /* SHORT TopEdge; */
  152.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  153.    ByteCount,  /* UBYTE *IText; */
  154.    NULL        /* struct IntuiText *NextText; */
  155. };
  156.  
  157. char OBlockCount[20];                                                         /* 13 June 1992 */
  158. static struct IntuiText OBlockCt =                                            /* 13 June 1992 */
  159. {
  160.    1, 0,       /* UBYTE FrontPen, BackPen; */
  161.    JAM2,       /* UBYTE DrawMode; */         
  162.    126,        /* SHORT LeftEdge; */                                          /* 13 June 1992 */
  163.    40,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  164.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  165.    OBlockCount,                                                               /* 13 June 1992 */
  166.                /* UBYTE *IText; */                                            /* 13 June 1992 */
  167.    &ByteCt     /* struct IntuiText *NextText; */
  168. };
  169.  
  170. char FBlockCount[20];                                                         /* 13 June 1992 */
  171. static struct IntuiText FBlockCt =                                            /* 13 June 1992 */
  172. {
  173.    1, 0,       /* UBYTE FrontPen, BackPen; */
  174.    JAM2,       /* UBYTE DrawMode; */
  175.    126,        /* SHORT LeftEdge; */                                          /* 13 June 1992 */
  176.    50,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  177.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  178.    FBlockCount,                                                               /* 13 June 1992 */
  179.                /* UBYTE *IText; */                                            /* 13 June 1992 */
  180.    &OBlockCt   /* struct IntuiText *NextText; */                              /* 13 June 1992 */
  181. };
  182.  
  183. char DirCount[20];
  184. static struct IntuiText DirCt =
  185. {
  186.    1, 0,       /* UBYTE FrontPen, BackPen; */
  187.    JAM2,       /* UBYTE DrawMode; */
  188.    294,        /* SHORT LeftEdge; */                                          /* 13 June 1992 */
  189.    30,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  190.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  191.    DirCount,   /* UBYTE *IText; */
  192.    &FBlockCt   /* struct IntuiText *NextText; */                              /* 13 June 1992 */
  193. };
  194.  
  195. char FileCount[20];
  196. static struct IntuiText FileCt =
  197. {
  198.    1, 0,       /* UBYTE FrontPen, BackPen; */
  199.    JAM2,       /* UBYTE DrawMode; */
  200.    246,        /* SHORT LeftEdge; */                                          /* 13 June 1992 */
  201.    40,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  202.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  203.    FileCount,  /* UBYTE *IText; */
  204.    &DirCt      /* struct IntuiText *NextText; */                              /* 13 June 1992 */
  205. };
  206.  
  207. static struct IntuiText Error =
  208. {
  209.    1, 0,       /* UBYTE FrontPen, BackPen; */
  210.    JAM2,       /* UBYTE DrawMode; */
  211.    5,          /* SHORT LeftEdge; */
  212.    80,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  213.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  214.    "Sizer failed.  Select close gadget to exit.",
  215.                /* UBYTE *IText; */
  216.    NULL        /* struct IntuiText *NextText; */
  217. };
  218.  
  219. static struct IntuiText Done2 =
  220. {
  221.    1, 0,       /* UBYTE FrontPen, BackPen; */
  222.    JAM2,       /* UBYTE DrawMode; */
  223.    5,          /* SHORT LeftEdge; */
  224.    80,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  225.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  226.    "Select close gadget to exit.",
  227.                /* UBYTE *IText; */
  228.    NULL        /* struct IntuiText *NextText; */
  229. };
  230.  
  231. static struct IntuiText Done =
  232. {
  233.    1, 0,       /* UBYTE FrontPen, BackPen; */
  234.    JAM2,       /* UBYTE DrawMode; */
  235.    5,          /* SHORT LeftEdge; */
  236.    70,         /* SHORT TopEdge; */                                           /* 13 June 1992 */
  237.    &TOPAZ80,   /* struct TextAttr *ITextFont; */                              /* 13 June 1992 */
  238.    "Program completed.",
  239.                /* UBYTE *IText; */
  240.    &Done2      /* struct IntuiText *NextText; */
  241. };
  242.  
  243. /* Initialize a NewWindow structure. */
  244. static struct NewWindow NewWindow =
  245. {
  246.    0, 10,            /* SHORT LeftEdge, TopEdge */
  247.    350, 90,          /* SHORT Width, Height */                                /* 13 June 1992 */
  248.    0, 1,             /* UBYTE DetailPen, BlockPen */
  249.    CLOSEWINDOW,      /* ULONG IDCMPFlags */
  250.    WINDOWDRAG + WINDOWDEPTH + WINDOWCLOSE + SMART_REFRESH + NOCAREREFRESH,
  251.                      /* ULONG Flags */
  252.    NULL,             /* struct Gadget *FirstGadget */
  253.    NULL,             /* struct Image *CheckMark */
  254.    "Sizer v1.2",     /* UBYTE *Title */                                       /* 13 June 1992 */
  255.    NULL,             /* struct Screen *Screen */
  256.    NULL,             /* struct BitMap *BitMap */
  257.    0, 0,             /* SHORT MinWidth, MinHeight */
  258.    0, 0,             /* USHORT MaxWidth, MaxHeight */
  259.    WBENCHSCREEN      /* USHORT Type */
  260. };
  261.  
  262.  
  263. static int                                                                    /* 18 May 1992 */
  264. CheckClose(struct Window *Window)
  265. {
  266.    ULONG class;
  267.    int flag = 0;
  268.    struct IntuiMessage *message = NULL;
  269.  
  270.    while (message = (struct IntuiMessage *)GetMsg(Window->UserPort))
  271.    {
  272.       class = message->Class;
  273.       ReplyMsg((struct Message *)message);
  274.  
  275.       if (class == CLOSEWINDOW)
  276.          flag = 1;
  277.    }
  278.    return(flag);
  279. }
  280.  
  281.  
  282. void
  283. SizerIO(struct record *Record)
  284. {
  285.    static struct Window *Window = NULL;
  286.    extern struct IntuitionBase *IntuitionBase;
  287.  
  288.    if (Window == NULL)
  289.    /* If the window isn't already open we'll try to open it.  If we can't we
  290.       will pass a "FAIL" code back to the calling program so it will stop
  291.       executing.
  292.    */
  293.    {
  294.       if (NULL == (IntuitionBase = (struct IntuitionBase *)
  295.                                    OpenLibrary("intuition.library",
  296.                                    INTUITION_REV)))
  297.       {
  298.          Record->code = FAIL;
  299.          return;
  300.       }
  301.       if ((Window = OpenWindow(&NewWindow)) == NULL)
  302.       {
  303.          CloseLibrary((struct Library *)IntuitionBase);
  304.          Record->code = FAIL;
  305.          return;
  306.       }
  307.       /* Write the fixed text to the window.
  308.       */
  309.       PrintIText(Window->RPort, &Files, 0, 0);                                /* 13 June 1992 */
  310.    }
  311.  
  312.    /* Write the number of bytes and blocks in the window.
  313.    */
  314.    sprintf(ByteCount, "%ld", Record->bytes);
  315.    sprintf(OBlockCount, "%ld", Record->OFSblocks);                            /* 13 June 1992 */
  316.    sprintf(FBlockCount, "%ld", Record->FFSblocks);                            /* 13 June 1992 */
  317.    sprintf(FileCount, "%ld", Record->files);
  318.    sprintf(DirCount, "%ld", Record->dirs);
  319.    PrintIText(Window->RPort, &FileCt, 0, 0);
  320.  
  321.    switch(Record->code)
  322.    {
  323.    case CLOSEIO:
  324.    /* If Record->code == CLOSEIO the program has finished with the window.
  325.       Close the window and the library.
  326.    */
  327.       CloseWindow(Window);
  328.       Window = NULL;
  329.       CloseLibrary((struct Library *)IntuitionBase);
  330.       break;
  331.    case FAIL:
  332.    /* If Record->code == FAIL write an error message to the window and wait
  333.       for the user to close the window.
  334.    */
  335.       PrintIText(Window->RPort, &Error, 0, 0);
  336.       WaitClose(Window);
  337.       break;
  338.    case DONE:
  339.    /* If Record->code == DONE write a completion message to the window and
  340.       wait for the user to close the window.
  341.    */
  342.       PrintIText(Window->RPort, &Done, 0, 0);
  343.       WaitClose(Window);
  344.       break;
  345.    default:
  346.    /* If the user closed the window set Record->code to FAIL.
  347.    */
  348.       if (CheckClose(Window) == 1)
  349.          Record->code = FAIL;
  350.    }
  351.    /* Return to the calling program.
  352.    */
  353.    return;
  354. }
  355.  
  356.  
  357. static void                                                                   /* 18 May 1992 */
  358. WaitClose(struct Window *Window)
  359. {
  360.    int done = 0;
  361.  
  362.    while (done == 0)
  363.    {
  364.       Wait(1L << Window->UserPort->mp_SigBit);
  365.       done = CheckClose(Window);
  366.    }
  367. }
  368.